import React, { createRef, forwardRef, PureComponent } from 'react'

const HelloWorld = forwardRef(function(props, ref) {
  return (
    <div>
      <h1 ref={ref}>Hello World</h1>
      <p>函数式组件</p>
    </div>
  )
})

export default class App extends PureComponent {
  constructor() {
    super()
    this.state = {}

    this.helloworldRef = createRef()
  }
  handleClick() {
    console.log(this.helloworldRef.current)
  }
  render() {
    return (
      <div>
        <HelloWorld ref={this.helloworldRef} />
        <button onClick={() => this.handleClick()}>获取DOM</button>
      </div>
    )
  }
}
